	 function addNumberOfOption(counter)
	 {
		var html = '';
		var error_msg = '';
		var option_counter = parseInt(document.getElementById("option_counter").value);
		var to_counter = option_counter+1;
		document.getElementById("option_counter").value = to_counter;
			html +=  "<div id= \"div_"+to_counter+"\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"10%\" align=\"left\" ><strong>Option " +to_counter+"</strong></td>"; 
					
			html +=  "<td width=\"60%\" align=\"left\" valign=\"middle\">&nbsp;<input type=\"text\" name= \"option[]\" id= \"options_id_"+to_counter+"\">";
					html +=  "</td>";
					html += "<td width=\"20%\" align=\"center\"><span><a href='javascript:void(0)' onclick='updateAnswer("+to_counter+")'>Make it Answer</a></span><a href=\"javascript:removeElement("+to_counter+");\" class=\"close_span\" >&nbsp;</a></td></tr></table></div>";
					//alert(html);
					document.getElementById('show_no_of_option').innerHTML +=  html;
		    //}llop
	  // }
	 }// end function 
	 
	 
	 function updateAnswer(counter){
		  
		 $('#answer').val(  $('#options_id_'+counter).val() ) ; 
	 }
	 function removeElement(id)
	 {
		  //updateNoOfOption();
		 // updateNoOfOption(id);
		  $('#div_'+id).remove();
		
     }//end function
	 
	
	//this functin check valid charactar in the trivia option 
	function ch_triviaValue(str)
	{ 
		var pattern = /^([a-zA-Z0-9\s\?-])+$/; 
		if( pattern.test(str) )
			return true;
		else
			return false;
	}//end function 
	
	//This ajax base  function is used to remove options from database
	
	function removeTriviaOptions(quiz_option_id){
	   $('#div_remove_option').html('<img src="../templates/admin/images/loading.gif">');	
	   $.post(
		 baseurl+"/admin/trivia.php", 
		 { action: "remove_trivia_option", quiz_option_id : quiz_option_id }, 
		 function(data){ 
		       
		         $('#div_remove_option').html(data);      
		 } 
		);
	}
	function triviaFrmValidation(){
	         var error_msg = '';
		 	 var question = jQuery.trim(document.getElementById('question').value);
			 var answer = jQuery.trim(document.getElementById('answer').value);
			 var question_date = jQuery.trim(document.getElementById('question_date').value);
			 var question_id = jQuery.trim(document.getElementById('question_id').value);
			 var option_counter = parseInt(document.getElementById('option_counter').value);
			 var option = document.getElementsByName('option[]');
			 var sum_no_option = '';   
			 var flag = 1;
			 var count = 1;
     	     
		
	  
		if(question==''){
			error_msg += '<p>Please enter  question.</p>';
			
		}
		if(question!='' && (!ch_triviaValue(question))){
			
			error_msg += '<p>Invalid characters, please enter valid characters in  question.</p>';
			
		}
		
		if ( option.length == 0 ||  option.length == 1) {
			error_msg += '<p>Please enter atleast 2 options for answers .</p>';
		}
		else		
		if( option.length > 5 )	{
			error_msg += '<p>Maximun no of option should be 5.</p>';
		}	
		
			  
			   for (var i = 0; i < option.length; i++){
				 if(option[i].value!= '' ){
					flag++;	 
				 }
				 var tot_value = count++
				 if((option[i].value!= '')&&(!ch_triviaValue(option[i].value))){
					 error_msg += '<p>Invalid characters, please enter valid characters in option '+tot_value+'.</p>';
				 }
				
				 if (flag==tot_value){
					error_msg += '<p>please enter option'+tot_value+'.</p>';
				   
				}
				
			
			  }//end for loop
		if(answer==''){
				
				error_msg += '<p>Please enter answer.</p>';
				
			}
			
			if(question_date==''){
				
				error_msg += '<p>Please enter question date.</p>';
				
			}
		
		if(error_msg == '')
		{
			$('#main_error_div').html('');	
			$('#main_error_div').hide();
			return true;
		}
		else
		{
			$('#main_error_div').html(error_msg);
			$('#main_error_div').show();
			return false;
		}
	}//end function triviaFrmValidation
	